package com.itheima.springbootmybatisdemo.mapper;

import com.itheima.springbootmybatisdemo.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * TODO
 *
 * @Author mr.luo
 * @Date 03 4月 2025 12:11
 */
@Mapper
public interface UserMapper {

    /**
     * 查询所有用户
     *
     * @return
     */
//    @Select("select * from emp")
    public List<User> findAll();


    /**
     * 根据id删除用户
     *
     * @param id
     * @return
     */
//   @Delete("delete from emp where id = #{id}")
//   public Integer deleteById1(Integer id);
    @Delete("delete from emp where id = #{uid}")
    public Integer deleteById2(@Param("uid") Integer id);

    /**
     * 添加用户
     *name;
     *  gender;
     * telephone;
     *  departmentId;
     *  salary;
     * photo;
     * birthday;
     * createTime;
     * updateTime;
     * @param user
     * @return
     */
    @Insert("insert into emp( username, password, name, gender, phone, job, salary, image, entry_date, create_time, update_time)" +
            " values(#{username},#{password},#{name}, #{gender}, #{phone}, #{job}, #{salary}, #{image}, #{entryDate}, #{createTime},#{updateTime})")
 public Integer insertUser(User user);


    /**
     * 根据id修改用户
     *
     * @param user
     * @return
     */
    @Update("update emp set username = #{username}, password = #{password}, name = #{name}, " +
            "gender = #{gender}, phone = #{phone}, job = #{job}, salary = #{salary}, image = #{image} where id = #{id}")
    public Integer updateUser(User user);


    /**
     * 根据username与密码查询用户
     *
     * @param
     * @return
     */
    @Select("select * from emp where username = #{username} and password = #{password}")
    public User findByIdAndPassword(@Param("username")  String username, @Param("password") String password);


    /**
     * 先查询然后再删除
     *
     * @param
     * @return
     */
//    @Delete("DELETE FROM emp WHERE id IN (SELECT id FROM emp WHERE gender = #{gender})")
    public Integer deleteByGender(@Param("salary") Integer salary);

}
